<?php

class devicecontroller extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('devicemodel');
    }

    public function adddevice()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');

        $this->form_validation->set_rules('device_id', 'device_id', 'required');
        $this->form_validation->set_rules('serial_id', 'serial_id', 'required');
        $this->form_validation->set_rules('invoice_id', 'invoice_id', 'required');
        $this->form_validation->set_rules('disk', 'disk', 'required');
        $this->form_validation->set_rules('memory', 'memory', 'required');
        $this->form_validation->set_rules('processor', 'processor', 'required');
        $this->form_validation->set_rules('purchase_date', 'purchase_date', 'required');
        $this->form_validation->set_rules('replacement_date', 'replacement_date', 'required');
        $this->form_validation->set_rules('waranty_expiry', 'waranty_expiry', 'required');
        $this->form_validation->set_rules('waranty_years', 'waranty_years', 'required');
        $this->form_validation->set_rules('region', 'region', 'required');
        $this->form_validation->set_rules('location', 'location', 'required');
        $this->form_validation->set_rules('comments', 'comments', 'required');


        if ($this->form_validation->run() === FALSE) {
            $this->load->view('devices/adddevice');

        } else {
            $this->devicemodel->addDevice();
            $this->load->view('devices/addsuccess');

        }

    }

    public function getDeviceData()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('device_id', 'device_id', 'required');

        if ($this->form_validation->run() === FALSE) {
            $this->load->view('devices/editdevice');
        } else {
            $data['datareceived'] = $this->devicemodel->getData();
            $this->load->view('devices/edit', $data);

        }
    }

    public function updateData()
    {
        $this->devicemodel->updateData();
        $this->load->view('devices/updatesuccess');

    }

    public function view()
    {
        $data['devices'] = $this->devicemodel->view();
        $this->load->view('devices/view', $data);
    }
}

?>